package forum.server.persistence.old;

import forum.server.domain.Post;
import forum.server.domain.PostContent;
import java.util.Date;

/*
 * This class is used to convert the posts to a table like form for the data base.
 */
public class PostTableEntry {
	
    private int postId;
    private int parentId;
    private String header;
    private Date createdDate;
    private Date modifiedDate;
    private String authorUsername;
    private PostContent content;
    
    /**
     * default Constructor.
     */
    public PostTableEntry() {
        this.postId = -1;
        this.parentId = -1;
        this.header = null;
        this.createdDate = null;
        this.modifiedDate = null;
        this.authorUsername = null;
        this.content = null;
    }
    
    /**
     * Constructor.
     * @param p the post to initialize to.
     */
    public PostTableEntry(Post p){
        this.postId=p.getPostId();
        this.parentId=p.getParentId();
        this.header=p.getHeader();
        this.createdDate=p.getCreateDate();
        this.modifiedDate=p.getModifiedDate();
        this.authorUsername=p.getAuthor();
        this.content=p.getContent();
    }

    /**
     * This function converts PostTableEntry to Post.
     */
    public static Post tableEntryToPost(PostTableEntry entry){
        return new Post(entry.getAuthorUsername(), entry.getHeader(), 
        		entry.getContent(), entry.getPostId(), entry.getParentId(), 
        		entry.getCreatedDate(), entry.getModifiedDate());
    }
    
    /**
     * getter for the authorUsername field.
     * @return the authorUsername.
     */
    public String getAuthorUsername() {
        return this.authorUsername;
    }
    
    /**
     * getter for the content field.
     * @return the content.
     */
    public PostContent getContent() {
        return this.content;
    }
    
    /**
     * getter for the createdDate field.
     * @return the createdDate.
     */
    public Date getCreatedDate() {
        return this.createdDate;
    }
    
    /**
     * getter for the header field.
     * @return the header.
     */
    public String getHeader() {
        return this.header;
    }
    
    /**
     * getter for the modifiedDate field.
     * @return the modifiedDate.
     */
    public Date getModifiedDate() {
        return this.modifiedDate;
    }
    
    /**
     * getter for the parentId field.
     * @return the parentId.
     */
    public int getParentId() {
        return this.parentId;
    }
    
    /**
     * getter for the postId field.
     * @return the postId.
     */
    public int getPostId() {
        return this.postId;
    }
    
    /**
     * setter for the authorUsername field.
     * @param authorUsername the new username.
     */
    public void setAuthorUsername(String authorUsername) {
        this.authorUsername = authorUsername;
    }
    
    /**
     * setter for the content field.
     * @param content the new content.
     */
    public void setContent(PostContent content) {
        this.content = content;
    }
    
    /**
     * setter for the createdDate field.
     * @param createdDate the new date.
     */
    public void setCreatedDate(Date createdDate) {
        this.createdDate = createdDate;
    }
    
    /**
     * setter for the header field.
     * @param header the new header.
     */
    public void setHeader(String header) {
        this.header = header;
    }
    
    /**
     * setter for the modifiedDate field.
     * @param modifiedDate the new date.
     */
    public void setModifiedDate(Date modifiedDate) {
        this.modifiedDate = modifiedDate;
    }
    
    /**
     * setter for the parentId field.
     * @param parentId the new parent Id.
     */
    public void setParentId(int parentId) {
        this.parentId = parentId;
    }
    
    /**
     * setter for the postId field.
     * @param postId the new postId.
     */
    public void setPostId(int postId) {
        this.postId = postId;
    }  
}
